#include "keyboard.h"

Action keyboard_event(ALLEGRO_EVENT &ev,Action &action, bool arrow_keys[4], bool &shoot_key, bool &pause_key, bool &exit_key, bool &is_exit)
{
	//------------------------------------------
	//Down Keys Events
	//------------------------------------------
	if(ev.type == ALLEGRO_EVENT_KEY_DOWN && !shoot_key)
	{
		switch(ev.keyboard.keycode)
		{
			case ALLEGRO_KEY_UP:		arrow_keys[UP] = true;		return action = MOVE_UP;		break;
			case ALLEGRO_KEY_DOWN:		arrow_keys[DOWN] = true;	return action = MOVE_DOWN;		break;
			case ALLEGRO_KEY_RIGHT:		arrow_keys[RIGHT] = true;	return action = MOVE_RIGHT;	break;
			case ALLEGRO_KEY_LEFT:		arrow_keys[LEFT] = true;	return action = MOVE_LEFT;		break;
			case ALLEGRO_KEY_SPACE:		shoot_key = true;			return action = SHOOT;			break;
			case ALLEGRO_KEY_X:			shoot_key = true;			return action = SHOOT;			break;
			default:					cout<<"INVALID KEY SELECTION"<<endl;
		}
	}

	//------------------------------------------
	//Up Key Events
	//------------------------------------------
	else if(ev.type == ALLEGRO_EVENT_KEY_UP)
	{
		switch(ev.keyboard.keycode)
		{
			case ALLEGRO_KEY_UP:		arrow_keys[UP] = false;		break;
			case ALLEGRO_KEY_DOWN:		arrow_keys[DOWN] = false;	break;
			case ALLEGRO_KEY_RIGHT:		arrow_keys[RIGHT] = false;	break;
			case ALLEGRO_KEY_LEFT:		arrow_keys[LEFT] = false;	break;
			case ALLEGRO_KEY_SPACE:		shoot_key = false;			break;
			case ALLEGRO_KEY_X:			shoot_key = false; 			break;
			case ALLEGRO_KEY_ESCAPE:	is_exit = true;				break;		
			case ALLEGRO_KEY_P:			pause_key = !pause_key;		break;
			default:					cout<<"INVALID KEY SELECTION"<<endl;
		}
	}																						

	//------------------------------------------
	//No Keys Pressed Update
	//------------------------------------------
	if(!arrow_keys[0]&&!arrow_keys[1]&&!arrow_keys[2]&&!arrow_keys[3]&&!shoot_key) 
	{
		return action = NO_ACTION;
	}

}

void resetKeys(ALLEGRO_EVENT &ev,Action &action, bool arrow_keys[4], bool &shoot_key, bool &pause_key, bool &exit_key, bool &is_exit)
{
	 action = NO_ACTION; 
	 arrow_keys[UP] = false; 
	 arrow_keys[DOWN] = false; 
	 arrow_keys[LEFT] = false; 
	 arrow_keys[RIGHT] = false; 
	 shoot_key = false; 
	 pause_key = false;
	 exit_key = false;
	 is_exit = false;

}